package com.com.yunzong.rainbowbridge.network;




import android.text.TextUtils;

import com.yz.jdd.base.MyApplication;
import com.yz.jdd.base.entity.Response_Base;
import com.yz.jdd.network.MySubscriber;

import java.io.File;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by zark on 2018/1/23.
 * Desc:
 */

public class NetWorkUtil {
    public static void doHeartBeat( Request_Heartbeat request_Heartbeat,Subscriber subscriber) {

        Bridge_RetrofitUtils.getApiObservable().doHeartBeat(request_Heartbeat)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);

    }

    public static void  doVoiceBatchCallBack(List<Request_CallBack> request_callBacks,Subscriber subscriber){
        Bridge_RetrofitUtils.getApiObservable().doVoiceBatchCallBack(request_callBacks)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }
    /**
     * 语音播报回调
     * @param request_callBack
     * @param subscriber
     */
    public static void doVoiceCallBack(Request_CallBack request_callBack, Subscriber subscriber) {

        Bridge_RetrofitUtils.getApiObservable().doVoiceCallBack(request_callBack)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);

    }

    /**
     * 操作上报
     *
     * @param subscriber
     * @param request_operate
     */
    public static void doCallBack(Request_Operate request_operate, Subscriber subscriber) {
        Bridge_RetrofitUtils.getApiObservable().doCallBack(request_operate)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);

    }

    /**
     * 上传文件到服务器
     * @param file
     * @param subscriber
     */
//    public static void agentUploadFile(File file, Subscriber subscriber) {
//
//        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
//        builder.addFormDataPart("deviceId", MyApplication.imei);
//        builder.addFormDataPart(file.getName(), file.getName(),
//                RequestBody.create(MediaType.parse("multipart/form-data"), file));
//
//        Bridge_RetrofitUtils.getApiObservable().agentUploadFile(builder.build())
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(subscriber);
//    }


    /**
     * 策略回传
     * @param id
     * @param status
     * @param msg
     * @param filePath
     * @param batchId
     * @param type
     */
    public static void  doCallBack(String id, Integer status, String msg, String filePath, String batchId,int type){
        Request_Operate request_operate = new Request_Operate();

        //主键
        request_operate.setId(id);
        //2成功，3失败
        request_operate.setStatus(status);

        //原因，失败时候的原因
        if (!TextUtils.isEmpty(msg)) {
            request_operate.setReason(msg);
        }

        //url 7牛地址
        if (!TextUtils.isEmpty(filePath)) {
            request_operate.setFilePath(filePath);
        }

        if (!TextUtils.isEmpty(batchId)) {
            request_operate.setBatchId(batchId);
        }
        request_operate.setType(type);
        NetWorkUtil.doCallBack(request_operate, new MySubscriber() {
            @Override
            public void onSuccess(Response_Base response_baseModel) {

            }

            @Override
            public void onNeedLogin(String msg) {

            }

            @Override
            public void onFail(Response_Base response_baseModel) {

            }
        });
    }
}
